<xsl:stylesheet version="1.0"
	xmlns:date="http://exslt.org/dates-and-times" xmlns:ebe="http://cks/ebemethods"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="date ebe">

	<xsl:param name="IsBlogOwner" />
	<xsl:param name="RelativeUrl" />

	<xsl:output omit-xml-declaration="yes" />

	<xsl:template match="/">
		<div id="content" class="posts">	
			<!-- <xmp><xsl:copy-of select="."/></xmp> -->
			<xsl:apply-templates select="rows/row"/>
			
			<div class="clear flat"></div>
		</div>	
	</xsl:template>

	<xsl:template match="row">
		<xsl:variable name="publishedDate" select="date:parseDate(PublishedDate, 'yyyy-MM-dd HH:mm:ss')"/>

		<h2>
			<a title="{Title}" href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}">
				<xsl:value-of select="Title"/>
			</a>
		</h2>
	
		<h4>
			<xsl:value-of select="date:format-date($publishedDate, 'MMMM d, yyyy')"/>
			&#183;
			Posted by
			<xsl:value-of select="substring-after(Author,'#')"/>	
			&#183;
			<a href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}" title="Comments">
				<xsl:value-of select="NumComments"/> Comment<xsl:if test="NumComments != 1">s</xsl:if>
			</a>
		</h4>
		
		<xsl:if test="$IsBlogOwner = 'True'">
			<a href="/{substring-after(FileDirRef,'#')}/EditPost.aspx?ID={ID}">
				[Edit Post]
			</a>
		</xsl:if>

		<div class="entry">
			<p>
				<xsl:value-of select="Body" disable-output-escaping="yes"/>
			</p>
		</div>
		
		<p class="tagged">
			<span class="add_comment">
				&#8594; <a href="{ebe:createPostUrl(PublishedDate, BlogTitleForUrl)}" title="Comment on {Title}"><xsl:value-of select="NumComments"/> Comment<xsl:if test="NumComments != 1">s</xsl:if></a>
			</span>
			<strong>Tags:</strong>
			<xsl:call-template name="TagLoop"><xsl:with-param name="tag" select="MultiCategory" /></xsl:call-template>
		</p>		

		<p>&#160;</p>
		<p>&#160;</p>
		<p>&#160;</p>
	</xsl:template>

<!-- a recursive template to replace character delimiters in tags -->
<xsl:template name="TagLoop">
	<xsl:param name="tag" />
	<xsl:variable name="tag_after" select="substring-after($tag, ';#')" />
	
	<xsl:choose>
		<!-- display next tag and call template recursivly -->
		<xsl:when test="contains($tag_after, ';#')">
			<xsl:variable name="tag_before" select="substring-before($tag_after, ';#')" />
			<a href="{ebe:createTagUrl($tag_before)}" title="View all posts in {$tag_before}" rel="category tag"><xsl:value-of select="$tag_before" /></a> &#183;
			<xsl:call-template name="TagLoop">
				<xsl:with-param name="tag" select="substring-after($tag_after, ';#')" />
			</xsl:call-template>
		</xsl:when>
		<!-- display last tag -->
		<xsl:otherwise>
			<a href="{ebe:createTagUrl($tag_after)}" title="View all posts in {$tag_after}" rel="category tag"><xsl:value-of select="$tag_after"/></a>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>
